import { request } from 'umi';
import { NodeEntity } from './entities';
import { RequestResponse } from 'umi-request';

const route = '/system_info';

export async function listNodeOption() {
  return new Promise<OptionEntity[]>((resolve, reject) => {
    listNode().then((res) => {
      const { data } = res;
      resolve(data.map((item) => ({ label: item.node_name, value: item.node_name })))
    }).catch((e) => {
      reject(e)
    })
  })
}

export async function listNode() {
  return await request<RequestResponse<NodeEntity[]>>(`${route}/list_node_info`, {
    method: 'GET',
  });
}

export async function getMetric(nodeName: string[], metricNames: string[]) {
  return await request(`${route}/query_metrics`, {
    method: 'GET',
    params: {
      node_lists: nodeName.join(','),
      metric_names: metricNames.join(',')
    },
    skipErrorHandler: true,
  });
}